package com.kzj.fun.graph;

import com.kzj.common.exception.ExceptionEnum;
import com.kzj.common.exception.SystemException;
import com.kzj.fun.graph.Rectangle;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class SpecialRect extends Rectangle {

    public SpecialRect(Point point1, Point point2) {
        super(point1, point2, 2,Color.BLUE,false);
    }
    private final Color broderColor=Color.BLUE;
    private final Color externalColor=Color.WHITE;
    private final int broderStoker=4;
    private final int circleRadius=10;
    private final int externalRadius=4;
    @Override
    public void draw(Graphics g) {
        if(g instanceof  Graphics2D){
            Graphics2D g2d=(Graphics2D) g;
            // 启用抗锯齿
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            List<Point> pointList=new ArrayList<Point>();
            pointList.add(new Point(x,y));
            pointList.add(new Point(x+width/2,y));
            pointList.add(new Point(x+width,y));
            pointList.add(new Point(x,y+height/2));
            pointList.add(new Point(x+width,y+height/2));
            pointList.add(new Point(x,y+height));
            pointList.add(new Point(x+width/2,y+height));
            pointList.add(new Point(x+width,y+height));
            g2d.setColor(broderColor);
            g2d.setStroke(new BasicStroke(broderStoker));
            g2d.drawRect(x,y,width,height);
            for(int i=0;i<pointList.size();i++){
                Point point=pointList.get(i);
                int r=circleRadius+externalRadius;
                g2d.setColor(externalColor);
                g2d.fillOval(point.x-r/2,point.y-r/2,r,r);
                g2d.setColor(broderColor);
                g2d.fillOval(point.x-circleRadius/2,point.y-circleRadius/2,circleRadius,circleRadius);
            }
        }else throw new SystemException(ExceptionEnum.INNER_PARAM_EXCEPTION);
    }
}
